package controller;

import model.Card;
import view.UI;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class MouseLis implements MouseListener {
    private Controller controller;

    public Controller getController() {
        return controller;
    }

    public void setController(Controller controller) {
        this.controller = controller;
    }

    public MouseLis(Controller controller) {
        this.controller = controller;
    }

    // 用于标记牌是否已经点击过
    private boolean isCardClicked = false;
    private int originalY;

    public void mouseClicked(MouseEvent e) {
        // 判断鼠标点击的是左键
        if (e.getButton() == MouseEvent.BUTTON1) {
            // 获取点击到的资源对象
            Object source = e.getSource();

            if (source instanceof Card) {
                Card clickedCard = (Card) source;

                    if (clickedCard.isClicked()) {
                        // 恢复位置
                        clickedCard.setLocation(clickedCard.getX(), originalY);

                        clickedCard.setClicked(false);
                    } else {
                        // 保存原始位置
                        originalY = clickedCard.getY();

                        // 修改位置
                        clickedCard.setLocation(clickedCard.getX(), clickedCard.getY() - 50);

                        // 设置点击标记
                        clickedCard.setClicked(true);
                    }
            }
        }
        UI.enterGameJFrame.enterGameJPanel.repaint();
    }



    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }

}